#ifndef TP_FT3168_h
#define TP_FT3168_h

#include <Wire.h>
#include "Arduino.h"

struct Config_t {
  int pin_scl = -1;
  int pin_sda = -1;
  int pin_rst = -1;
  int pin_int = -1;
  bool pull_up_en = false;

  TwoWire* i2c_wire;
  uint32_t clk_speed = 100000;

  uint8_t dev_addr = 0x38;
};

struct TouchPoint_t {
  uint8_t event = 0;
  uint8_t id = 0;
  int x = -1;
  int y = -1;
};

class TP_FT3168 {
private:
  Config_t _cfg;
  bool _inited;
  uint8_t _data_buffer[7];

  bool _writeReg(uint8_t reg, uint8_t data);
  void _readReg(uint8_t reg, uint8_t readSize);
  void _initSetup();

public:
  TP_FT3168();
  ~TP_FT3168();

  void config(const Config_t& cfg);
  void setPin(int sda, int scl, int rst, int intr);
  void gpioInit();
  bool init(int sda, int scl, int rst = -1, int intr = -1, bool initI2C = true, uint32_t speed = 100000);
  // bool init(bool initI2C);
  bool isTouched();
  void getTouchRaw(TouchPoint_t& tp);
};



#endif
